import java.awt.*;

public class WallExplode {
    private int x, y, w, h;
    private boolean live = true;
    private int step = 0;
    private static final int DURATION = 10; // 爆炸持续帧数
    private TankClient tc;

    public WallExplode(int x, int y, int w, int h, TankClient tc) {
        this.x = x;
        this.y = y;
        this.w = w;
        this.h = h;
        this.tc = tc;
    }

    public void draw(Graphics g) {
        if (!live) {
            return;
        }

        Color c = g.getColor();
        g.setColor(Color.ORANGE);

        int maxRadius = Math.max(w, h) / 2;
        int centerX = x + w / 2;
        int centerY = y + h / 2;

        // 动态变化的爆炸大小
        int currentRadius = (int)((double)step / DURATION * maxRadius);

        g.fillOval(centerX - currentRadius, centerY - currentRadius, currentRadius * 2, currentRadius * 2);

        step++;
        if (step >= DURATION) {
            live = false;
            tc.wallExplodes.remove(this);
        }

        g.setColor(c);
    }

    public boolean isLive() {
        return live;
    }
}
